/*
 * @Descripttion:
 * @Author: Wang Dejiang(aei)
 * @Date: 2022-04-12 19:37:09
 * @LastEditors: Wang Dejiang(aei)
 * @LastEditTime: 2022-04-23 15:50:01
 */

import { Component } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Other from '../views/Other.vue'
import { useAfterEach, useBeaforeEach } from './guards'

interface Router {
  path: string
  name: string
  component: Component
  children?: Router[]
  meta?: {
    title: string
    keepAlive?: boolean // 需要被缓存
  }
}

const routes: Router[] = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [],
  },
  {
    path: '/other',
    name: 'Other',
    component: Other,
    children: [],
    meta: {
      title: '其他',
    },
  },
  {
    path: '/guide',
    name: 'Guide',
    component: () => import('../views/Guide.vue'),
    children: [],
    meta: {
      title: '指南',
    },
  },
  {
    path: '/apis',
    name: 'Apis',
    component: () => import('../views/Apis.vue'),
    children: [],
    meta: {
      title: 'api文档',
    },
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue'),
    children: [],
    meta: {
      title: '关于',
    },
  },
]

export const router = createRouter({
  history: createWebHistory(),
  routes,
})

router.beforeEach(useBeaforeEach)
router.afterEach(useAfterEach)
